<?php

namespace App\Admin\Controllers;

use App\Models\SwtTransferOrderBuyer;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SwtTransferOrderBuyerController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(SwtTransferOrderBuyer::with(['order','buyer']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('order_sn');
            $grid->column('order.order_sn','转让订单号') ->copyable();
            $grid->column('buyer.realname','买家');
            $grid->column('pay_status') -> using(['支付中','已支付','已完成','已取消']) -> label(['info','pink','success','warning']);
            $grid->column('cancel_desc');
            $grid->column('lock_at','锁定时间');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });

            $grid->disableActions();
            $grid->disableCreateButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SwtTransferOrderBuyer(), function (Show $show) {
            $show->field('id');
            $show->field('order_id');
            $show->field('order_sn');
            $show->field('buyer_id');
            $show->field('pay_status');
            $show->field('cancel_desc');
            $show->field('lock_at');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SwtTransferOrderBuyer(), function (Form $form) {
            $form->display('id');
            $form->text('order_id');
            $form->text('order_sn');
            $form->text('buyer_id');
            $form->text('pay_status');
            $form->text('cancel_desc');
            $form->text('lock_at');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
